import React, { Component } from 'react';
import { Route, Redirect } from 'react-router-dom';
import { connect } from 'react-redux'
import * as types from '@/typings/commonType'

@connect(null, {
  setShowPageFooter(show = false) {
    return { type: types.COMMON_SHOWPAGEFOOTER, payload: show }
  }
})
class PrivteRoute extends Component {
  render() {
    let { path, component: Cmp } = this.props
    return (
      <Route path={path} render={router => {
        this.props.setShowPageFooter(false)
        // 判断当前页面是否需要登录才能访问
        if (!sessionStorage.getItem('token') && path != '/login') {
          return <Redirect to='/login' />
        }
        return <Cmp {...router} />
      }} />
    );
  }
}

export default PrivteRoute;
